package main

import (
	"fmt"
	"strings"
)

func longestCommonPrefix(strs []string) string {
	if len(strs) == 0 {
		return ""
	}

	if len(strs) == 1 {
		return strs[0]
	}

	base := strs[0]
	for i := 1; i < len(strs); i++ {
		for !strings.HasPrefix(strs[i], base) {
			base = base[:len(base)-1]
		}
	}
	return base
}

func main() {
	fmt.Println(longestCommonPrefix([]string{"dog", "racecar", "car"}))
}
